package com.example.param;

import com.example.param.entity.User;
import com.example.param.mapper.UserMapper;
import com.example.param.model.PageResponse;
import com.example.param.model.UserQuery;
import com.example.param.util.MyBatisUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class App {
    public static void main(String[] args) {
        SqlSession session = MyBatisUtils.getSession();
        UserMapper mapper = session.getMapper(UserMapper.class);

        // 构造分页 + 查询参数
        UserQuery query = new UserQuery();
        query.setPageNum(2);
        query.setPageSize(5);
        query.setName("用户_0"); // 模糊匹配
        query.setStatus("enabled");
        query.setSortBy("age");
        query.setOrder("desc");

        // 开启分页，查询
        PageHelper.startPage(query.getPageNum(), query.getPageSize());
        List<User> list = mapper.searchUsers(query);
        PageInfo<User> pageInfo = new PageInfo<>(list);

        // 封装统一分页响应
        PageResponse<User> response = new PageResponse<>(pageInfo);
        System.out.println("统一分页响应结构：\n" + response);

        session.close();
    }
}